package top.kaoshanji.t1ch11a;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;
import java.util.logging.Logger;

/**
 * @author kaoshanji
 * ^_^
 * create time 2025/5/1 14:21
 */
@RestController
public class PaymentsController {

    private static Logger logger = Logger.getLogger(PaymentsController.class.getName());

    /**
     * 代码清单-t1ch11a-01：一个API接口示例
     * @param requestId 请求头
     * @param payment 请求参数
     * @return 响应体
     */
    @PostMapping("/createPayment")
    public ResponseEntity<Payment> createPayment(@RequestHeader String requestId, @RequestBody Payment payment) {
        logger.info("请求ID：" + requestId + "；支付金额：" + payment.getAmount());

        payment.setId(UUID.randomUUID().toString());

        return ResponseEntity.status(HttpStatus.OK).header("requestId", requestId).body(payment);
    }


}
